package threadDemo;

public class Test4 {
    public static void main(String[] args) throws InterruptedException {
        new NewThread();
        try{
            for(int i=5;i>0;i--){
                System.out.println("Main Thread: "+i);
                Thread.sleep(100);
            }
        }catch (InterruptedException e){
            System.out.println("Main thread interrupted");
        }
        System.out.println("Main thread exiting");
    }
}

class NewThread implements Runnable{
    Thread t;
    NewThread() throws InterruptedException {
        // 创建第二个新线程
        t = new Thread(this,"Demo Thread");
        System.out.println("Child thread: " + t);
        t.start();
    }
    @Override
    public void run() {

        try {
            for (int i = 5; i > 0; i--) {
                System.out.println("Child Thread: " + i);
                Thread.sleep(5000);
                System.out.println("正在执行的线程对象的引用"+Thread.currentThread().getName());
                System.out.println(t.getName()+"   "+t.isAlive());
                }
            }catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("Child interrupted.");
                }
                System.out.println("Exiting child thread");
    }
}
